﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace Sherwood.SignOn.Server.Models.Services
{
    public class Log
    {
        public static bool DebugEnabled
        {
            get
            {
                bool debugEnabled = false;
                if (bool.TryParse(System.Configuration.ConfigurationManager.AppSettings["LogDebugEnabled"], out debugEnabled))
                {
                    return debugEnabled;
                }
                return false;
            }
        }

        public static string FileName
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["LogFileName"];
            }
        }

        public static void Debug(string logLine)
        {
            if (DebugEnabled && FileName != null)
            {
                try
                {
                    logLine = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss\t") + logLine;
                    StreamWriter sw = new StreamWriter(new FileStream(FileName, FileMode.Append));
                    sw.WriteLine(logLine);
                    sw.Flush();
                    sw.Close();
                }
                catch { }
            }
        }

    }
}